import * as homeApi from '@/api/homepage.js';
export default {
  namespaced: true,
  state() {
    return {
      goodsList: [],
      homeBrandList: [],
      homeHotList: [],
      // 首页导航栏数据
      homepageHeadList: [],
      homeNewList: [],
      homepageBannerList: [],
    };
  },
  mutations: {
    GOODS(state, newValue) {
      state.goodsList = newValue;
    },
    HOMEBRAND(state, newValue) {
      state.homeBrandList = newValue;
    },
    HOMEHOT(state, newValue) {
      state.homeHotList = newValue;
    },
    HOMEPAGE(state, newValue) {
      state.homepageHeadList = newValue;
    },
    HOMENEW(state, newValue) {
      state.homeNewList = newValue;
    },
    HOMEPAGEBANNER(state, newValue) {
      state.homepageBannerList = newValue;
    },
  },
  actions: {
    // 获取首页商品列表
    async updateGoodsList({ commit }) {
      const res = await homeApi.goodsList();
      commit('GOODS', res);
    },
    // 轮播图
    async updateHomeBrandList({ commit }) {
      const res = await homeApi.homepageBrandList();
      commit('HOMEBRAND', res);
    },
    // 热门品牌
    async updateHomeHotList({ commit }) {
      const res = await homeApi.homepageHotList();
      commit('HOMEHOT', res);
    },
    // 首页头部
    async updateHomePageList({ commit }) {
      const res = await homeApi.homepageHeadList();
      commit('HOMEPAGE', res);
    },
    // 新品首发
    async updateHomeNewList({ commit }) {
      const res = await homeApi.homepageNewList();
      commit('HOMENEW', res);
    },
    // 首页banner
    async updateHomePageBannerList({ commit }) {
      const res = await homeApi.homepageBannerList();
      commit('HOMEPAGEBANNER', res);
    },
  },
};
